<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@page import="com.cap.bts.framework.usermgnt.constant.EmployeeStatus"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>套餐启用</title>
<%@include file="../include/include.jsp"%>
<link rel="stylesheet" type="text/css" href="${csspath }/public.css" />
<script type="text/javascript" src="${jspath}/jquery/jquery-2.1.3.js"></script>
<link rel="stylesheet" type="text/css"
	href="${bootstrapPath}/css/bootstrap.css" />
<script type="text/javascript" src="${bootstrapPath}/js/bootstrap.js"></script>
<script type="text/javascript" src="${layerPath }/layer.js"></script>
</head>

<script type="text/javascript">
	$(function() {
		//查询套餐信息
		$("#queryInfo_btn")
				.click(
						function() {
							search_form.action = "${webcontext}/crmdp/dealer/meal/getMealList?temp=enabled&pager.currentPage=1";
							document.getElementById("search_form").submit();
						});
	});

	//分页的查询
	function search() {
		search_form.action = "${webcontext}/crmdp/dealer/meal/getMealList?temp=enabled";
		document.getElementById("search_form").submit();
	}

	//查看套餐详情
	function queryMealDetails(id) {
		$("#id").val(id);
		$("#search_form").attr('action',
				'${webcontext}/crmdp/dealer/meal/toEditMealPage?temp=details');
		$("#search_form").submit();
	}

	//修改操作
	function editMealInfo(id, temp) {
		var info = null;
		if ("enabled" == temp) {
			info = "启用";
		} else if ("anabled" == temp) {
			info = "停用";
		}
		jConfirm(
				"确定要" + info + "这个套餐吗",
				"提示",
				function(r) {
					if (r == true) {
						$
								.ajax({
									url : '${webcontext}/crmdp/dealer/meal/packageEnabled',
									type : 'post',
									data : {
										'name' : $("#name").val(),
										'code' : $("#code").val(),
										'id' : id
									},
									success : function(data) {
										if (data.code == true) {
											jAlert(
													data.msg,
													"提示",
													function() {
														search_form.action = "${webcontext}/crmdp/dealer/meal/getMealList?temp=enabled";
														document
																.getElementById(
																		"search_form")
																.submit();
													});
										} else if (data.code == false) {
											jAlert(data.msg, "提示");
										}
									},
									error : function() {
										jAlert("服务器错误，请联系管理员", "提示");
									},
								});
					}
				});
	}

	window.onload = function() {
		var qStatus = '${qStatus}';
		if (qStatus != null && qStatus != "") {
			$("#qStatus").val(qStatus);
		}
	};
</script>

<style>
.icon {
	color: #FFFFFF;
}

.btnLength {
	width: 50px;
}
</style>
<body>
	<div id="content">
		<div style="margin-top: 20px;">
			<form:form id="search_form"
				action="${webcontext}/crmdp/dealer/meal/getMealList"
				class="form-inline" method="post" modelAttribute="dto">
				<input type="hidden" id="id" name="id">
				<div class="text-center">
					<div class="form-group">
						<label for="qCode">套餐编号</label> <input
							class="form-control input-sm" style="width: 200px;" id="qCode"
							name="qCode" type="text" value="${qCode}" />
					</div>
					<div class="form-group">
						<label for="qName">套餐名称</label> <input
							class="form-control input-sm" style="width: 200px;" id="qName"
							name="qName" type="text" value="${qName}" />
					</div>
					<div class="form-group">
						<label for="qStatus">套餐状态</label> <select id="qStatus" name="qStatus"
							class="form-control input-sm" style="width: 200px;">
							<option value="99">--------请选择--------</option>
							<option value="0">未启用</option>
							<option value="1">有效</option>
							<option value="2">停用</option>
						</select>
					</div>
				</div>
				<div class="text-center" style="margin-top: 20px;">
					<button id="queryInfo_btn" type="button"
						class="btn btn-success btn-sm">
						<i class="glyphicon glyphicon-search icon"></i>&nbsp;查询
					</button>
				</div>
				<table id="data_tabs" class="table"
					style="width: 100%; margin-top: 20px;">
					<thead>
						<tr>
							<th class="hidden" width="4%">套餐ID</th>
							<th class="hidden" width="4%">优惠券ID</th>
							<th width="5%">套餐编号</th>
							<th width="15%">套餐名称</th>
							<th width="6%">是否预付费</th>
							<th width="5%">建议零售价</th>
							<th width="3%" class="hidden">够买次数</th>
							<th width="6%">状态</th>
							<th width="6%">有效期</th>
							<th width="10%">操作</th>
						</tr>
					</thead>
					<tbody>
						<core:forEach items="${mealList}" var="list">
							<tr>
								<td class="hidden">${list.id}</td>
								<td class="hidden">${list.cardDefId}</td>
								<td>${list.code}</td>
								<td>${list.name}</td>
								<td><core:choose>
										<core:when test="${list.isPrepaymentCard =='0'}">
											<%=CodeTextUtils.getText("meal.isPrepaymentCard", 0)%>
										</core:when>
										<core:when test="${list.isPrepaymentCard =='1'}">
											<%=CodeTextUtils.getText("meal.isPrepaymentCard", 1)%>
										</core:when>
									</core:choose></td>
								<td class="text-right"><fmt:formatNumber
										value="${list.price}" pattern="##,###.##"
										minFractionDigits="1"></fmt:formatNumber></td>
								<td class="text-right hidden">${list.numberSequence}</td>
								<td><core:choose>
										<core:when test="${list.status=='0'}">
											<%=CodeTextUtils.getText("meal.Status", 0)%>
										</core:when>
										<core:when test="${list.status=='1'}">
											<%=CodeTextUtils.getText("meal.Status", 1)%>
										</core:when>
										<core:when test="${list.status=='2'}">
											<%=CodeTextUtils.getText("meal.Status", 2)%>
										</core:when>
									</core:choose></td>
								<td>${list.validPeriod}<core:choose>
										<core:when test="${list.unitOfPeriod=='Y'}">
											年
										</core:when>
										<core:when test="${list.unitOfPeriod=='M'}">
											月
										</core:when>
										<core:when test="${list.unitOfPeriod=='D'}">
											天
										</core:when>
									</core:choose></td>
								<td><button type="button"
										class="btn btn-success btn-xs btnLength"
										onClick="queryMealDetails('${list.id}')">详情</button> <core:choose>
										<core:when test="${list.status=='0'}">
											<button type="button"
												class="btn btn-success btn-xs btnLength"
												onClick="editMealInfo('${list.id}','enabled')">启用</button>
										</core:when>
										<core:when test="${list.status=='1'}">
											<button type="button"
												class="btn btn-success btn-xs btnLength"
												onClick="editMealInfo('${list.id}','anabled')">停用</button>
										</core:when>
										<core:when test="${list.status=='2'}">
											<button type="button"
												class="btn btn-success btn-xs btnLength"
												onClick="editMealInfo('${list.id}','enabled')">启用</button>
										</core:when>
									</core:choose></td>
							</tr>
						</core:forEach>
					</tbody>
				</table>
				<div class="page_div">
					<%@include file="../common/page.jsp"%>
				</div>
			</form:form>
		</div>
	</div>
</body>
</html>